define(function(require, exports, module) {
    "require:nomunge,exports:nomunge,module:nomunge";

    var app = require('mokit/app');
    var user = require('../models/User');
    var RegView = require('../views/reg');
    var lang = require('mokit/language');
    var navigation = require('mokit/navigation');
    var commonUtils = require('../common/utils');
    var utils = require('mokit/utils');
    var langMgr = require('mokit/language');

    /**
     * 登陆页控制器
     */
    return app.controller.create({

        /**
         * 默认action
         */
        index: function(context) {
            var self = this;
            //显示主视图
            self.setView(new RegView({
                model: user
            }));
        },

        reg: function(context) {
            var self = this;
            var regInfo = context.view.getInfo(context);
            user.reg(regInfo, function(err) {
                if (err) {
                    commonUtils.alert(err);
                    return;
                } else {
                    commonUtils.alert("注册成功", function() {
                        //自动填上账号和密码
                        user.account = regInfo.account;
                        user.password = regInfo.password;
                        //返回
                        self.back(context, '/login');
                    });
                    return;
                }
            });
        }

    });

});